#!/bin/bash
if [ $# -lt 1 ];
then
    echo "please input aicard id, like sh function_kill.sh 0 for card0"
    exit
fi

cardid=`expr $1`

MAIN_PROCESS="card_id_$cardid"

echo ${MAIN_PROCESS}
lock_file=/tmp/test_func.lock_all

function kill(){
    result=`ps -ef | grep -E $1 | grep -v grep | wc -l`
    while ((result>0))
    do
        result=`ps -ef | grep ""$1"" | grep -v grep`
        echo $result
        result=`ps -ef | grep $1 | grep -v grep | wc -l`
        if [[ result -gt 0 ]];
        then   
            ps -ef | grep $1 | grep -v grep | awk '{print $2}' | xargs kill -9
            sleep 1 
        fi
    done
    echo "card_id_$cardid killed" >> $lock_file
}

kill $MAIN_PROCESS
